package cn.jtfadmin.base.dict.controller;


import cn.jtfadmin.base.dict.dto.DictItemModelDTO;
import cn.jtfadmin.base.dict.dto.DictModelDTO;
import cn.jtfadmin.base.dict.service.DictService;
import cn.jtfadmin.base.lang.common.domain.dto.ResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典管理
 *
 * @author jtf
 * @since 1.0
 */
@RestController
@Validated
public class DictController {


    @Autowired
    private DictService dictService;


    /**
     * 获取字典数据
     *
     * @param dictCode 字典code
     * @return
     */
    @RequestMapping(value = "/base/dict/getDictItems/{dictCode}", method = RequestMethod.GET)
    public ResultDTO<List<DictItemModelDTO>> getDictItems(@PathVariable String dictCode) {
        List<DictItemModelDTO> dictItemModelList = dictService.findDictItemModelByCode(dictCode);
        return ResultDTO.successData(dictItemModelList);
    }

    /**
     * @param name
     * @param describe
     * @return
     */
    @GetMapping(value = "/base/dict/list")
    public ResultDTO<List<DictModelDTO>> list(String name, String describe) {
        return ResultDTO.successData(dictService.findAll(name, describe));
    }
}
